<?php

// no direct access
defined('_JEXEC') or die('Restricted access');

// Import Joomla! libraries
jimport('joomla.application.component.model');

require_once JPATH_ADMINISTRATOR.DS.'components'.DS.'com_eventcalendar'.DS.'helpers'.DS.'database.php';

class TableKalenteri extends JTable
{
   
    var $id = null;
	var $nimi = null;
    var $moderaattori_id = null;
    var $readonly = null;	
    var $julkinen= null;
   
 
    function __construct( &$db ) {
        parent::__construct('#__kalenteri', 'id', $db);
    }
}

	

class EventcalendarsModelAddcalendar extends JModel 
{
	function alustaDb()
	{
		$joku = new DatabaseHelper();
		$option = $joku->get('option');
		
		$db = & JDatabase::getInstance( $option );
		$this->setDBO($db);
	}

    function __construct() 
	{
		parent::__construct();
		$this->alustaDb();
    }

	  var $_data;
 
    /**
     * Returns the query
     * @return string The query to be used to retrieve the rows from the database
     */
    function _buildQuery()
    {
        $query = ' SELECT * '
            . ' FROM #__kalenteri'
        ;
        return $query;
    }
 
    /**
     *
     * @return array Array of objects containing the data from the database
     */
    function getData()
    {
        // Lets load the data if it doesn't already exist
        if (empty( $this->_data ))
        {
            $query = $this->_buildQuery();
            $this->_data = $this->_getList( $query );
        }
 
        return $this->_data;
    }

	function saveCalendar()
	{
	
		$kalenteri =& $this->getTable('kalenteri');
		
		$nimi = $_POST['nimi'];
		 $moderaattori = $_POST['moderaattori_id'];
		 $julkinen = $_POST['julkinen'];
		 $read_only = $_POST['readonly'];
		 
		 
		 $kalenteri =& JTable::getInstance('kalenteri', 'Table');
		 $db = $this->getDBO();
		$kalenteri->setDBO($db);
			
		 $kalenteri->nimi = $nimi;
		 $kalenteri->moderaattori_id = $moderaattori;
		 $kalenteri->julkinen = $julkinen;
		 $kalenteri->readonly = $read_only;
		
		$kalenteri->store();
		
		
		return $kalenteri->id;
	}
	
}


?>